<?php
require '../includes/common.php';
header('Content-type:text/html;charset=utf-8');
if(!$login) exit("请先登录");
if(!empty($_GET['phone']) && !empty($_GET['display']) && !empty($_GET['target'])){
	$phone=daddslashes($_GET['phone']);
	$display=daddslashes($_GET['display']);
	$target=daddslashes($_GET['target']);
	if(strlen($phone)!=11||strlen($target)!=11)
		exit('<div class="alert alert-warning"><img src="../assets/img/ico_tip.png">&nbsp;手机号码格式不正确！</div>');
		if($userrow['vip']==0){
			if($userrow['money']<$conf['tell_money']) exit('<div class="alert alert-warning"><img src="../assets/img/ico_tip.png">&nbsp;余额不足</div>');
			}
			
	$data=curl_get('http://phone.kfj.cc/api.php?authcode='.$authcode.'&phone='.$phone.'&display='.$display.'&target='.$target);
	$arr=json_decode($data,true);
	if($arr['code']==1){
		if($userrow['vip']==0){
				$money = $conf['tell_money'];
			
			}elseif($userrow['agent']){
				$dl = $DB->get_row("select * from tell_level where id='{$userrow['agent']}' limit 1");
				$money = $dl['price'];
				var_dump($money);
				}
				$DB->query("update tell_users set money=money-$money where id='{$userrow['id']}' limit 1");
		echo '<div class="alert alert-success"><img src="../assets/img/ico_success.png">&nbsp;'.$arr['msg'].'</div>';
	}else{
		exit('<div class="alert alert-warning"><img src="../assets/img/ico_tip.png">&nbsp;'.$arr['msg'].'</div>');
	}
	$DB->query("insert into `tell_log` (`phone`,`display`,`target`,`time`,`km`) values ('".$phone."','".$display."','".$target."','".time()."','".$km."')");
}else{
	exit('<div class="alert alert-warning"><img src="../assets/img/ico_tip.png">&nbsp;请确保各项不能为空</div>');
}